<?php
/**
 * 正则匹配字符串中的数字
 * @param $string
 * @return mixed
 */
function myExplodeNumbers($string)
{
    preg_match_all("/[0-9\.?]+/",$string,$array);
    return $array[0];
}


function createOrderSn($uid = "")
{
    return date("YmdHis").rand(1000,9999).$uid;
}

function createPayCalBackCode($uid,$type="wx")
{
    return md5($type.uniqid($uid).rand(1000,9999));
}
function dealWithImgInHtml($content,$basUrl)
{
    $pregRule = "/<[img|IMG].*?src=[\'|\"](.*?(?:[\.jpg|\.jpeg|\.png|\.gif|\.bmp]))[\'|\"].*?[\/]?>/";
    $content = preg_replace($pregRule, '<img src="'.$basUrl.'${1}" style="max-width:100%">', $content);
    return $content;
}
function dealWithPhoneNumber($phone)
{
    $start = substr($phone,0,3);
    $end = substr($phone,-4);
    return $start."****".$end;
}
function dealWithHtmlContent($content,$len = 250)
{
    $content = strip_tags($content);
    if (mb_strlen($content) > $len) {
        return mb_substr($content,0,$len)."...";
    }else{
        return $content;
    }
}

function getFileExtension($fileName)
{
    $arr = explode(".",$fileName);
    return $arr[array_key_last($arr)];
}

function idToValue($id,$choices){
    foreach ($choices as $choice) {
        if ($id == $choice["id"]) {
           return $choice["value"];
        }
    }
    return '';
}

/**
 * @param $text
 * @param $color
 * @param $backGround
 * @return string
 */
function textColor($text,$color,$backGround){
    $style="";
    switch ($color) {
        case "f";
            $style.="color: #fafafa;";break;
        case "0";
            $style.="color: #424242;";break;
        case "Red";
            $style.="color: #f44336;";break;
        case "Pink";
            $style.="color: #e91e63;";break;
        case "Purple";
            $style.="color: #9c27b0;";break;
        case "Deep Purple";
            $style.="color: #673ab7;";break;
        case "Indigo";
            $style.="color: #3f51b5;";break;
        case "Blue";
            $style.="color: #2196f3;";break;
        case "Light Blue";
            $style.="color: #03a9f4;";break;
        case "Cyan";
            $style.="color: #00bcd4;";break;
        case "Teal";
            $style.="color: #009688;";break;
        case "Green";
            $style.="color: #4caf50;";break;
        case "Light Green";
            $style.="color: #8bc34a;";break;
        case "Lime";
            $style.="color: #cddc39;";break;
        case "Yellow";
            $style.="color: #ffeb3b;";break;
        case "Amber";
            $style.="color: #ffc107;";break;
        case "Orange";
            $style.="color: #ff9800;";break;
        case "Deep Orange";
            $style.="color: #ff5722;";break;
        case "Brown";
            $style.="color: #795548;";break;
        case "Blue Grey";
            $style.="color: #607d8b;";break;
        case "Grey";
            $style.="color: #9e9e9e;";break;
        default:
//            $style.="color: #424242;";break;
    }
    switch ($backGround) {
        case "0";
            $style.="background-color:#424242;";break;
        case "f";
            $style.="background-color:#fafafa;";break;
        case "Red";
            $style.="background-color:#f44336;";break;
        case "Pink";
            $style.="background-color:#e91e63;";break;
        case "Purple";
            $style.="background-color:#9c27b0;";break;
        case "Deep Purple";
            $style.="background-color:#673ab7;";break;
        case "Indigo";
            $style.="background-color:#3f51b5;";break;
        case "Blue";
            $style.="background-color:#2196f3;";break;
        case "Light Blue";
            $style.="background-color:#03a9f4;";break;
        case "Cyan";
            $style.="background-color:#00bcd4;";break;
        case "Teal";
            $style.="background-color:#009688;";break;
        case "Green";
            $style.="background-color:#4caf50;";break;
        case "Light Green";
            $style.="background-color:#8bc34a;";break;
        case "Lime";
            $style.="background-color:#cddc39;";break;
        case "Yellow";
            $style.="background-color:#ffeb3b;";break;
        case "Amber";
            $style.="background-color:#ffc107;";break;
        case "Orange";
            $style.="background-color:#ff9800;";break;
        case "Deep Orange";
            $style.="background-color:#ff5722;";break;
        case "Brown";
            $style.="background-color:#795548;";break;
        case "Blue Grey";
            $style.="background-color:#607d8b;";break;
        case "Grey";
            $style.="background-color:#9e9e9e;";break;
        default:
//            $style.="background-color:#fafafa;";break;
    }
    return "<span style='border-radius: 5px; padding: 5px;{$style}'>{$text}</span>";
}

